# PlanetfallEntityRenders.py
# Planetfall Spells
#
# These are functions that are specifically made to render entities
# to the table in the entity-select function. The point is to create one
# function for each style of entity.
#
# An "entity" is something that can be selected w/ the entity-select scree.
# For example, a unit is an entity, and so the entity-select screen for a spell
# that targets a unit will want to render units to the screen. Another spell 
# might want the entities to be buildings in the city of the plot selected.
#
# Rather than make a new window for each type of "entity", the screen creates
# itself generically, and then calls the spell's file to fill in the table
# the contains all the data. To make things easier, this file will have 
# pre-built functions that can be used to "render", and it's just a matter 
# of passing the arguments off to the functions in this file to actually put 
# data into the entity-select screen.
#

from CvPythonExtensions import *
import CvUtil

gc = CyGlobalContext()
localtext = CyTranslator()
gameText = CyGameTextMgr()

##########
# Units
##########
def renderUnit(pEntityRow, pUnit):
    # Gets the height of the image
    iWidgetSize = pEntityRow.getPercentHeight(80)
    BUFFER = 5

    # Adds the unit image widget.
    pWidget = pEntityRow.createImageWidget()
    pWidget.setX(BUFFER)
    pWidget.setY(BUFFER)
    pWidget.setWidth(iWidgetSize)
    pWidget.setHeight(iWidgetSize)
    pWidget.setImage( gc.getUnitInfo(pUnit.getUnitType()).getButton() )
    pEntityRow.addWidget(pWidget)

    iSecondColumnStart = pEntityRow.getPercentWidth(14)
    iTextRowSeperation = pEntityRow.getPercentHeight(33)

    # Adds the unit name widget.
    pWidget = pEntityRow.createTextWidget()
    pWidget.setX(iSecondColumnStart)
    pWidget.setY(0)
    pWidget.setText( pUnit.getName() )
    pEntityRow.addWidget(pWidget)

    # Adds the level widget.
    pWidget = pEntityRow.createTextWidget()
    pWidget.setX(iSecondColumnStart)
    pWidget.setY(iTextRowSeperation * 1)
    pWidget.setText( localtext.getText("INTERFACE_PANE_LEVEL", () ) + " %d" % (pUnit.getLevel()))
    pEntityRow.addWidget(pWidget)

    # Adds the experience widget
    pWidget = pEntityRow.createTextWidget()
    pWidget.setX(iSecondColumnStart)
    pWidget.setY(iTextRowSeperation * 2)
    pWidget.setText( localtext.getText("INTERFACE_PANE_EXPERIENCE", () ) + ": %d/%d" % (pUnit.getExperience(), pUnit.experienceNeeded()) )
    pEntityRow.addWidget(pWidget)

    iThirdColumnStart = pEntityRow.getPercentWidth(40)

    # Adds the combat widget
    pWidget = pEntityRow.createTextWidget()
    pWidget.setX(iThirdColumnStart)
    pWidget.setY(iTextRowSeperation * 1)
    pWidget.setText("Blah")
    pEntityRow.addWidget(pWidget)

    iFourthColumnStart = pEntityRow.getPercentWidth(60)
    iPromoRowImages = 8
    iPromotionImageSize = 23
    iPromoNumber = 0

    getNextPromoX = lambda: iFourthColumnStart + (iPromotionImageSize * (iPromoNumber % iPromoRowImages))
    getNextPromoY = lambda: iPromotionImageSize * (iPromoNumber / iPromoRowImages)
    
    for i in range(gc.getNumPromotionInfos()):
        if (pUnit.isHasPromotion(i)):
            pWidget = pEntityRow.createImageWidget()
            pWidget.setX( getNextPromoX() )
            pWidget.setY( getNextPromoY() )
            pWidget.setWidth(iPromotionImageSize)
            pWidget.setHeight(iPromotionImageSize)
            pWidget.setImage( gc.getPromotionInfo(i).getButton() )
            pWidget.setHelpTextCallback(gameText.getPromotionHelp, (i, False) )
            pEntityRow.addWidget(pWidget)
            iPromoNumber += 1

############
# Buildings
############
def renderBuilding(pEntityRow, pCity, iBuildingTarget):
    iWidgetSize = pEntityRow.getPercentHeight(80)

    pWidget = pEntityRow.createImageWidget()
    pWidget.setX(5)
    pWidget.setY(5)
    pWidget.setWidth(iWidgetSize)
    pWidget.setHeight(iWidgetSize)
    pWidget.setImage(gc.getBuildingInfo(iBuildingTarget).getButton())
    pEntityRow.addWidget(pWidget)

    iSecondColumnStart = pEntityRow.getPercentWidth(60)
    pWidget = pEntityRow.createTextWidget()
    pWidget.setX(iSecondColumnStart)
    pWidget.setY(pEntityRow.getPercentHeight(30))
    pWidget.setText(gc.getBuildingInfo(iBuildingTarget).getDescription())
    pEntityRow.addWidget(pWidget)
    
            
            
